﻿<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>IntelliFlex Cloud Server | @ViewBag.Title</title>
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700' rel='stylesheet' type='text/css'>
    <!-- Add local styles, mostly for plugins css file -->
    @if (IsSectionDefined("Styles"))
    {@RenderSection("Styles", required: false)    }

    <!-- Add jQuery Style direct - used for jQGrid plugin -->
    <link href="@Url.Content("~/Scripts/plugins/jquery-ui/jquery-ui.css")" rel="stylesheet" type="text/css" />

    <!-- Primary Inspinia style -->
    @Styles.Render("~/font-awesome/css")
    @Styles.Render("~/Content/css")
    @Styles.Render("~/plugins/toastrStyles")
</head>
<body class="fixed-sidebar no-skin-config full-height-layout">

    <!-- Wrapper-->
    <!-- PageClass give you ability to specify custom style for specific view based on action -->
    <div id="wrapper" class="@Html.PageClass()">

        <!-- Navigation -->
        @Html.Partial("_Navigation_RTU_block")

        <!-- Page wraper -->
        <div id="page-wrapper" class="gray-bg @ViewBag.SpecialClass">

            <!-- Top Navbar -->
            @Html.Partial("_TopNavbar_RTU_block")

            <!-- Main view  -->
            @RenderBody()

            <!-- Footer -->
            @*@Html.Partial("_Footer_RTU")*@

        </div>
        <!-- End page wrapper-->
        <!-- Right Sidebar -->
        @Html.Partial("_RightSidebar_RTU")

    </div>
    <!-- End wrapper-->
    <!-- Section for main scripts render -->
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @Scripts.Render("~/plugins/slimScroll")
    @Scripts.Render("~/bundles/inspinia")
    @Scripts.Render("~/plugins/toastr")

    <!-- Skin config script - only for demo purpose-->
    @Scripts.Render("~/bundles/skinConfig")

    @Scripts.Render("~/plugins/i18next")

    <!-- Handler for local scripts -->
    @RenderSection("scripts", required: false)
    <script type="text/javascript">
        $(document).ready(function () {

            //$.i18n.init({
            //    resGetPath: '../locales/__lng__.json',
            //    load: 'unspecific',
            //    fallbackLng: false,
            //    lng: 'english'
            //}, function (t) {
            //    $('#side-menu').i18n();
            //    $('.navbar-top-links').i18n();
            //});

            sessionStorage.recordId = "";
            var blockDataUrl = '@Url.Action("Block", "Map")';
            var isLoginUrl = '@Url.Action("IsLogin", "Login")';
            if (sessionStorage.blockname == undefined) {
                //sessionStorage.blockname = "全部区块";
                sessionStorage.blockname = "All Reservoirs";
                sessionStorage.blockid = 0;
            }
            //$("#blockname").text("当前：" + sessionStorage.blockname);
            $("#blockname").text("Current:" + sessionStorage.blockname);
            nowTime();
            setInterval("nowTime()", 1000);
            $.ajax({
                url: blockDataUrl,
                method: 'GET',
                dataType: 'json',
                success: function (data) {
                    if (data.status == 7) { alert("权限出错") }
                    else {
                        var div = $('#blockpanel');
                        div.empty();
                        div.append(
                                //'<div class="setings-item sidebar-message"><div class="xds_text_center" onclick="goto(0,\'全部区块\')">全部区块</div></div>'
                                '<div class="setings-item sidebar-message"><div class="xds_text_center" onclick="goto(0,\'All Reservoirs\')">All Reservoirs</div></div>'
                                );
                        $.each(data.data, function (i, item) {
                            div.append(
                                '<div class="setings-item sidebar-message"><div class="xds_text_center" onclick="goto(' + item.ID + ',\'' + item.Name + '\')">' + item.Name + '</div></div>'
                                );
                            $("#map").append(
                                '<li class="@Html.IsSelected(action: "Index")' + item.ID + '"><a href="@Url.Action("Index", "Map")" onclick="changemap(' + item.ID + ',\'' + item.Name + '\')">' + item.Name + '</a></li>'
                                    );
                        })
                    }
                },
                error: function () {
                    alert("网络错误！请刷新后重试。")
                }
            });
            $.ajax({
                url: isLoginUrl,
                method: 'GET',
                dataType: 'json',
                success: function (data) {
                    if (data.status == 0) {
                        sessionStorage.username = data.name;
                    }
                }
            });
            refreshontime();
        })
        function refreshontime() {
            $.ajax({
                url: '/WarnLog/GetOnesWarn',
                type: 'post',
                dataType: 'json'
            }).success(function (result) {
                if (result.status == 0) {
                    var s = sessionStorage.recordId;
                    sessionStorage.recordId = "";
                    $.each(result.data, function (i, item) {
                        if (s.indexOf("-" + item.RecordeID + "-") > -1) {
                            sessionStorage.recordId = sessionStorage.recordId + "-" + item.RecordeID + "-";
                        }
                        else {
                            showtoast(item.WELL_ID, item.IDCode, item.RecordeID);
                            sessionStorage.recordId = sessionStorage.recordId + "-" + item.RecordeID + "-";
                        }
                    });
                }
            }).error(function () {
                alert("网络错误！请刷新后重试。")
            });
            setTimeout(refreshontime, 300000);
        }
        function showtoast(wellid, code, id) {
            toastr.options = {
                "closeButton": true,
                "progressBar": false,
                "newestOnTop": true,
                "showDuration": 1,
                "hideDuration": 0,
                "timeOut": 0,
                "tapToDismiss": false,
                "extendedTimeOut": 0
            }
            var $toast = toastr["warning"]('<div><a href="">油井' + wellid + '出现如下问题：' + code + '</a></div><div><button type="button" class="btn btn-primary" id="' + id + 'jump" style="margin-top:10px">查看</button><button type="button" class="btn" id="' + id + 'ignore" style="margin-top:10px;margin-left:50px">忽略</button></div>')
            var char1 = id + "jump";
            var char2 = id + "ignore";
            if ($toast.find('#' + char1).length) {
                $toast.delegate('#' + char1, 'click', function () {
                    $toast.remove();
                    sessionStorage.wellid = wellid;
                    $.ajax({
                        url: "/WellList/OneWellOfBlock",
                        method: 'GET',
                        dataType: 'json',
                        data: { wellid: wellid },
                        async: false,
                        success: function (data) {
                            if (data.status == 7) { alert("权限出错") }
                            else if (data.status == 0) {
                                sessionStorage.wellname = data.data.Name1;
                                window.open("/FirstPage/Index/", "_self");
                            }
                        },
                        error: function () {
                            alert("网络错误！请刷新后重试。")
                        }
                    });
                });
            }
            if ($toast.find('#' + char2).length) {
                $toast.delegate('#' + char2, 'click', function () {
                    $toast.remove();
                    ignorewarn(wellid, id);
                });
            }
        };

        function ignorewarn(wellid, id) {
            $.ajax({
                url: "/WarnLog/IgnoreWarn",
                method: 'GET',
                dataType: 'json',
                data: { wellid: id },
                async: false,
                success: function (data) {
                    if (data.status == 7) { alert("对不起，发生未知错误") }
                    else if (data.status == 0) {
                        alert("忽略" + wellid + "号井的报警成功");
                    }
                },
                error: function () {
                    alert("网络错误！请刷新后重试。")
                }
            });
        }
        //function nowTime() {
        //    var nowDate = new Date();
        //    var year = nowDate.getFullYear();
        //    var month = nowDate.getMonth() + 1;
        //    month = month > 9 ? month : "0" + month;
        //    var date = nowDate.getDate();
        //    date = date > 9 ? date : "0" + date;
        //    var hour = nowDate.getHours();
        //    hour = hour > 9 ? hour : "0" + hour;
        //    var miunte = nowDate.getMinutes();
        //    miunte = miunte > 9 ? miunte : "0" + miunte;
        //    var second = nowDate.getSeconds();
        //    second = second > 9 ? second : "0" + second;

        //    $("#nowtime").text(year + "年" + month + "月" + date + "日" + hour + "时" + miunte + "分" + second + "秒");
        //}
        function nowTime() {
            //参数i为时区值数字，比如北京为东八区则输进8,西5输入-5
            var d = new Date();
            var m = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Spt", "Oct", "Nov", "Dec");
            var w = new Array("Monday", "Tuseday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
            //得到1970年一月一日到现在的秒数
            var len = d.getTime();
            //本地时间与GMT时间的时间偏移差
            var offset = d.getTimezoneOffset() * 60000;
            //得到现在的格林尼治时间
            var utcTime = len + offset;
            var nowDate = new Date(utcTime + 3600000 * -5);
            var year = nowDate.getFullYear();
            //var month = nowDate.getMonth() + 1;
            //month = month > 9 ? month : "0" + month;
            month = m[nowDate.getMonth()]
            var week = w[nowDate.getDay() - 1];
            var date = nowDate.getDate();
            date = date > 9 ? date : "0" + date;
            var hour = nowDate.getHours();
            hour = hour > 9 ? hour : "0" + hour;
            var miunte = nowDate.getMinutes();
            miunte = miunte > 9 ? miunte : "0" + miunte;
            var second = nowDate.getSeconds();
            second = second > 9 ? second : "0" + second;

            $("#nowtime").text(week + "," + date + " " + month + " " + year + " " + hour + ":" + miunte + ":" + second + " EST");
            //$("#nowtime").text(nowDate);
        }
        function goto(id, name) {
            sessionStorage.blockid = id;
            sessionStorage.blockname = name;
            //$("#blockname").text("当前：" + sessionStorage.blockname);
            $("#blockname").text("Current:" + sessionStorage.blockname);
            refresh();
        }
        function changemap(id, name) {
            sessionStorage.blockid = id;
            sessionStorage.blockname = name;
        }
        function getKey() {
            if (event.keyCode == 13) {
                if ($("#top-search").val() == null)
                    alert("please input sth");
                else {
                    sessionStorage.searchstr = $("#top-search").val();
                    window.open("/WellList/Search");
                }
            }
        }
    </script>
</body>
</html>
